﻿
//=======================================================================
// <copyright file="Profile.cs" company="Samuel Chen Studio">
//     Copyright (c) Samuel Chen Studio. All rights reserved.
//     author   : Samuel Chen
//     version  : 1.0
//     contact  : http://www.SamuelChen.net, samuel.net@gmail.com
// </copyright>
//=======================================================================

using System;
using System.Xml;
using System.Reflection;
using System.Diagnostics;

namespace Net.SamuelChen.SharpTweet {
    public class Profile : TwitterObject {
        public string id = string.Empty;
        public string name = string.Empty;
        public string screen_name = string.Empty;
        public string location = string.Empty;
        public string description = string.Empty;
        public string profile_image_url = string.Empty;
        public string url = string.Empty;
        public bool @protected = false;
        public int followers_count = 0;
        public string profile_background_color = string.Empty;
        public string profile_text_color = string.Empty;
        public string profile_link_color = string.Empty;
        public string profile_sidebar_fill_color = string.Empty;
        public string profile_sidebar_border_color = string.Empty;
        public int friends_count = 0;
        public int favourites_count = 0;
        public DateTime created_at = DateTime.MinValue;
        public int utc_offset = 0;
        public string time_zone = string.Empty;
        public string profile_background_image_url = string.Empty;
        public string profile_background_tile = string.Empty;
        public int statuses_count = 0;
        public bool notifications = false;
        public bool following = false;
        public Status status = null;


        /// <summary>
        /// Retrive profile properties by parsing xml. Overrided parent's method. 
        /// </summary>
        /// <param name="content">The xml content string.</param>
        //public override void ParseXml(string content) {
        //    base.ParseXml(content);
        //    if (Unparsed.Count > 0) {
        //        if (Unparsed.Contains("status")) {
        //            status = Status.FromXml(Unparsed["status"].ToString());
        //            Unparsed.Remove("status");
        //        }
        //    }

        //}

        // TODO: refactor to APIUtility.cs
        public static Profile FromXml(string content) {
            Profile p = new Profile();
            try {
                p.ParseXml(content);
            } catch (Exception ex) {
                Trace.TraceWarning(ex.ToString());
                p = null;
#if DEBUG
                throw ex;
#endif
            }
            return p;
        }

        protected override object ParseUnknownTypeXML(XmlNode node, Type tagetType) {
            if (null == node)
                return null;

            string name = node.Name;    // property name
            if (string.Compare(name, "status", true) == 0) {
                Status s = Status.FromXml(node.OuterXml);
                return s;                
            } else
                return base.ParseUnknownTypeXML(node, tagetType);
        }

        // TODO: refactor to APIUtility.cs
        internal static Profile FromJson(string content) {
            throw new NotImplementedException();
        }
    }
}